from lzw import LZWGif


# 读 frame_data.bin 文件
def read_frame_data():
    with open('frame_data.bin', 'rb') as f:
        frame_data = f.read()
    return frame_data

def write_frame_data(data):
    with open('frame_data_decompressed.bin', 'wb') as f:
        f.write(data) 


lzw = LZWGif()

compress = read_frame_data()
print("Compressed length:", len(compress))


total_binary_string = ''
for b in compress:
    binary_string = ''.join(format(b, '08b'))
    total_binary_string = binary_string + total_binary_string

print(total_binary_string)

compress_index = []
idx = len(total_binary_string) 
size = 3
while idx >= 3:
    bit3_str = total_binary_string[idx-size:idx]
    num = int(bit3_str, 2)
    compress_index.append(num)
    idx -= size

# print("Decompressed length:", len(decompress))
# write_frame_data(decompress)
# print("Compress index length:", len(compress_index))
# print(compress_index)

decompress = lzw.decompress(compressed=compress_index)
# print(decompress)